/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PanelSupervisor.java
 *
 * Created on 27-dic-2011, 14:13:25
 */
package incidencias;

import accesoBD.*;
import idiomas.*;
import java.io.File;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Locale;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.JFileChooser;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

/**
 * Clase que muestra el rol de Supervisor
 * @author Cristian modified by Agustin Jiménez Fernández
 */
public class PanelSupervisor extends javax.swing.JFrame implements ListSelectionListener {

    private int parte;
    private Supervisor su;

    /**
     * Constructor del panel
     * @param q Objeto QuerySupervisor utilizado para hacer las consultas (que las hace el Supervisor)
     */
    public PanelSupervisor(QuerySupervisor q) {
        su = new Supervisor(q);
        initComponents();
        mantenimientoButton.setEnabled(false);
        empresaButton.setEnabled(false);
        pdfButton.setEnabled(false);
        cerrarButton.setEnabled(false);
        Locale.setDefault(Locale.getDefault());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel3 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        listModel = new DefaultListModel();
        try {
            ResultSet rset = Supervisor.getPartesAsignados();
            while (rset.next()) {
                listModel.addElement(rset.getInt(1));
            }
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(PanelSupervisor.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(PanelSupervisor.class.getName()).log(Level.SEVERE, null, ex);
        }
        jList1 = new JList();
        jList1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        jList1.setSelectedIndex(0);
        jList1.addListSelectionListener(this);
        jList1.setVisibleRowCount(5);
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        recargarButton = new javax.swing.JButton();
        listaLabel = new javax.swing.JLabel();
        parteLabel = new javax.swing.JLabel();
        lenguageSelect = new javax.swing.JComboBox();
        lenguageLabel = new javax.swing.JLabel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        mantenimientoButton = new javax.swing.JButton();
        empresaButton = new javax.swing.JButton();
        pdfButton = new javax.swing.JButton();
        notaLabel = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea2 = new javax.swing.JTextArea();
        jPanel3 = new javax.swing.JPanel();
        areaLabel = new javax.swing.JLabel();
        salaLabel = new javax.swing.JLabel();
        plantaLabel = new javax.swing.JLabel();
        pasilloLabel = new javax.swing.JLabel();
        salaTextField = new javax.swing.JTextField();
        plantaTextField = new javax.swing.JTextField();
        pasilloTextField = new javax.swing.JTextField();
        ubicacionButton = new javax.swing.JButton();
        ComboBoxModel = new DefaultComboBoxModel();
        try {
            ResultSet rset = Supervisor.getAreas();
            ComboBoxModel = new DefaultComboBoxModel();
            while (rset.next()) {
                ComboBoxModel.addElement(rset.getString(1));
            }
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(PanelSupervisor.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(PanelSupervisor.class.getName()).log(Level.SEVERE, null, ex);
        }
        areaComboBox = new javax.swing.JComboBox();
        jPanel2 = new javax.swing.JPanel();
        nameLabel = new javax.swing.JLabel();
        nombreTextField = new javax.swing.JTextField();
        codPublicoLabel = new javax.swing.JLabel();
        codpublicoTextField = new javax.swing.JTextField();
        codInternoLabel = new javax.swing.JLabel();
        codinternoTextField = new javax.swing.JTextField();
        marcaModel = new javax.swing.JLabel();
        marcaTextField = new javax.swing.JTextField();
        modeloLabel = new javax.swing.JLabel();
        modeloTextField = new javax.swing.JTextField();
        colorLabel = new javax.swing.JLabel();
        colorTextField = new javax.swing.JTextField();
        garantiaLabel = new javax.swing.JLabel();
        garantiaTextField = new javax.swing.JTextField();
        ubicacionLabel = new javax.swing.JLabel();
        aparatoButton = new javax.swing.JButton();
        ubicacionesBoxModel = new DefaultComboBoxModel();
        try {
            ResultSet rset = Supervisor.getUbicaciones();
            ubicacionesBoxModel = new DefaultComboBoxModel();
            while (rset.next()) {
                ubicacionesBoxModel.addElement(rset.getString(1));
            }
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(PanelSupervisor.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(PanelSupervisor.class.getName()).log(Level.SEVERE, null, ex);
        }
        jComboBox1 = new javax.swing.JComboBox();
        jPanel4 = new javax.swing.JPanel();
        aparatoLabel = new javax.swing.JLabel();
        descripcionLabel = new javax.swing.JLabel();
        aparatosBoxModel = new DefaultComboBoxModel();
        try {
            ResultSet rset = Supervisor.getAparatos();
            //ubicacionesBoxModel = new DefaultComboBoxModel();
            while (rset.next()) {
                aparatosBoxModel.addElement(rset.getString(1)+" : "+rset.getString(2) + " / " + rset.getString(3));
            }
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(PanelSupervisor.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(PanelSupervisor.class.getName()).log(Level.SEVERE, null, ex);
        }
        jComboBox2 = new javax.swing.JComboBox();
        jScrollPane4 = new javax.swing.JScrollPane();
        jTextArea3 = new javax.swing.JTextArea();
        enviarButton = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        salirButton = new javax.swing.JButton();
        tecnicosBoxModel = new DefaultComboBoxModel();
        try {
            ResultSet rset = Supervisor.getTecnicos();
            //tecnicosBoxModel = new DefaultComboBoxModel();
            tecnicosBoxModel.addElement("Todos");
            while (rset.next()) {
                tecnicosBoxModel.addElement(rset.getString(1)+":"+rset.getString(2));
            }
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(PanelSupervisor.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(PanelSupervisor.class.getName()).log(Level.SEVERE, null, ex);
        }
        tecnicosComboBox = new javax.swing.JComboBox();
        cerrarButton = new javax.swing.JButton();
        jScrollPane5 = new javax.swing.JScrollPane();
        listModel2 = new DefaultListModel();
        try {
            ResultSet rset = Supervisor.getPartesExternos();
            while (rset.next()) {
                listModel2.addElement(rset.getInt(1));
            }
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(PanelSupervisor.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(PanelSupervisor.class.getName()).log(Level.SEVERE, null, ex);
        }
        jList2 = new javax.swing.JList();
        jList2.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        jList2.setSelectedIndex(-1);
        jList2.addListSelectionListener(this);
        jList2.setVisibleRowCount(5);
        externoLabel = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/incidencias/masterlogo.png"))); // NOI18N

        jList1.setModel(listModel);
        jScrollPane3.setViewportView(jList1);

        jTextArea1.setColumns(20);
        jTextArea1.setEditable(false);
        jTextArea1.setLineWrap(true);
        jTextArea1.setRows(5);
        jTextArea1.setWrapStyleWord(true);
        jScrollPane1.setViewportView(jTextArea1);

        recargarButton.setText("Recargar Partes");
        recargarButton.setPreferredSize(new java.awt.Dimension(100, 40));
        recargarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                recargarButtonActionPerformed(evt);
            }
        });

        listaLabel.setText("Lista de Partes");

        parteLabel.setText("Parte No");

        lenguageSelect.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Español", "English" }));
        lenguageSelect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                lenguageSelectActionPerformed(evt);
            }
        });

        lenguageLabel.setText("Idioma");

        mantenimientoButton.setText("Tecnico");
        mantenimientoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mantenimientoButtonActionPerformed(evt);
            }
        });

        empresaButton.setText("Empresa Ext.");
        empresaButton.setPreferredSize(new java.awt.Dimension(100, 40));
        empresaButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                empresaButtonActionPerformed(evt);
            }
        });

        pdfButton.setText("Generar PDF");
        pdfButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pdfButtonActionPerformed(evt);
            }
        });

        notaLabel.setText("Nota adjunta");

        jTextArea2.setColumns(20);
        jTextArea2.setLineWrap(true);
        jTextArea2.setRows(5);
        jTextArea2.setWrapStyleWord(true);
        jScrollPane2.setViewportView(jTextArea2);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pdfButton, javax.swing.GroupLayout.DEFAULT_SIZE, 333, Short.MAX_VALUE)
                    .addComponent(notaLabel)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(mantenimientoButton, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(empresaButton, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE))
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 333, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(mantenimientoButton, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(empresaButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(pdfButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(notaLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(13, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Reasignar/Generar", jPanel1);

        areaLabel.setText("Area");

        salaLabel.setText("Sala");

        plantaLabel.setText("Planta");

        pasilloLabel.setText("Pasillo");

        ubicacionButton.setText("Agregar");
        ubicacionButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ubicacionButtonActionPerformed(evt);
            }
        });

        areaComboBox.setModel(ComboBoxModel);
        areaComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                areaComboBoxActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(areaLabel)
                            .addComponent(salaLabel)
                            .addComponent(plantaLabel)
                            .addComponent(pasilloLabel))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(areaComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(salaTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 139, Short.MAX_VALUE)
                            .addComponent(plantaTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 139, Short.MAX_VALUE)
                            .addComponent(pasilloTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 139, Short.MAX_VALUE)))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(126, 126, 126)
                        .addComponent(ubicacionButton)))
                .addContainerGap(156, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(areaLabel)
                    .addComponent(areaComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(salaLabel)
                    .addComponent(salaTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(plantaLabel)
                    .addComponent(plantaTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(pasilloLabel)
                    .addComponent(pasilloTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(58, 58, 58)
                .addComponent(ubicacionButton)
                .addContainerGap(79, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Ubicacion", jPanel3);

        nameLabel.setText("Nombre");

        codPublicoLabel.setText("Codigo Publico");

        codInternoLabel.setText("Codigo Interno");

        marcaModel.setText("Marca");

        modeloLabel.setText("Modelo");

        colorLabel.setText("Color");

        garantiaLabel.setText("Garantia");

        ubicacionLabel.setText("Ubicacion");

        aparatoButton.setText("Agregar");
        aparatoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aparatoButtonActionPerformed(evt);
            }
        });

        jComboBox1.setModel(ubicacionesBoxModel);
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(nameLabel)
                                .addGap(18, 18, 18)
                                .addComponent(nombreTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 278, Short.MAX_VALUE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(codPublicoLabel)
                                .addGap(18, 18, 18)
                                .addComponent(codpublicoTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 246, Short.MAX_VALUE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(codInternoLabel)
                                .addGap(18, 18, 18)
                                .addComponent(codinternoTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 243, Short.MAX_VALUE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(marcaModel)
                                    .addComponent(modeloLabel))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addGap(18, 18, 18)
                                        .addComponent(marcaTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 277, Short.MAX_VALUE))
                                    .addComponent(modeloTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 295, Short.MAX_VALUE)))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(colorLabel)
                                .addGap(19, 19, 19)
                                .addComponent(colorTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 157, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(garantiaLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(garantiaTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(ubicacionLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(118, 118, 118)
                        .addComponent(aparatoButton)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nameLabel)
                    .addComponent(nombreTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(codPublicoLabel)
                    .addComponent(codpublicoTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(codInternoLabel)
                    .addComponent(codinternoTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(6, 6, 6)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(marcaTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(marcaModel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(modeloTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(modeloLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(colorTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(colorLabel)
                    .addComponent(garantiaLabel)
                    .addComponent(garantiaTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(5, 5, 5)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ubicacionLabel)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(aparatoButton)
                .addContainerGap(69, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Aparato", jPanel2);

        aparatoLabel.setText("Aparato");

        descripcionLabel.setText("Descripción");

        jComboBox2.setModel(aparatosBoxModel);

        jTextArea3.setColumns(20);
        jTextArea3.setLineWrap(true);
        jTextArea3.setRows(5);
        jTextArea3.setWrapStyleWord(true);
        jScrollPane4.setViewportView(jTextArea3);

        enviarButton.setText("Enviar");
        enviarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                enviarButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 333, Short.MAX_VALUE)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(aparatoLabel)
                        .addGap(18, 18, 18)
                        .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 185, Short.MAX_VALUE)
                        .addComponent(enviarButton))
                    .addComponent(descripcionLabel))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(aparatoLabel)
                            .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(descripcionLabel))
                    .addComponent(enviarButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(31, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Crear Parte", jPanel4);

        jLabel5.setText("??");

        salirButton.setFont(new java.awt.Font("Tahoma", 0, 18));
        salirButton.setText("SALIR");
        salirButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                salirButtonActionPerformed(evt);
            }
        });

        tecnicosComboBox.setModel(tecnicosBoxModel);
        tecnicosComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tecnicosComboBoxActionPerformed(evt);
            }
        });

        cerrarButton.setText("Cerrar Parte");
        cerrarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cerrarButtonActionPerformed(evt);
            }
        });

        jList2.setModel(listModel2);
        jList2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jList2MouseClicked(evt);
            }
        });
        jScrollPane5.setViewportView(jList2);

        externoLabel.setText("Externo");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lenguageLabel)
                        .addGap(18, 18, 18)
                        .addComponent(lenguageSelect, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jScrollPane3, 0, 0, Short.MAX_VALUE)
                            .addComponent(externoLabel)
                            .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 118, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 412, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(listaLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(tecnicosComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(parteLabel)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel5)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(salirButton, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel3))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(recargarButton, javax.swing.GroupLayout.PREFERRED_SIZE, 208, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(cerrarButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lenguageLabel)
                    .addComponent(lenguageSelect, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(listaLabel)
                    .addComponent(tecnicosComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(parteLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(externoLabel)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 312, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(salirButton, javax.swing.GroupLayout.DEFAULT_SIZE, 67, Short.MAX_VALUE)
                                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 74, Short.MAX_VALUE))))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 395, javax.swing.GroupLayout.PREFERRED_SIZE)))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(recargarButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(cerrarButton, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * Controlador encargado de cambiar el lenguaje del panel
     * @param evt 
     */
    private void lenguageSelectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_lenguageSelectActionPerformed
        // TODO add your handling code here:
        String Idioma = "";
        //String Idioma = (String) lenguageSelect.getSelectedItem();
        switch (lenguageSelect.getSelectedIndex()) {
            case 0: //Español
                Idioma = "es";
                break;
            case 1: //Ingles
                Idioma = "en";
                break;
        }
        Locale locale = new Locale(Idioma);
        messages.setLocale(locale);
        lenguageLabel.setText(messages.getString("Language") + ":");
        empresaButton.setText(messages.getString("Company"));
        recargarButton.setText(messages.getString("ReassignParts"));
        aparatoButton.setText(messages.getString("agregate"));
        aparatoLabel.setText(messages.getString("device"));
        cerrarButton.setText(messages.getString("ClosePart"));
        listaLabel.setText(messages.getString("ListOfParts"));
        parteLabel.setText(messages.getString("PartNo"));
        mantenimientoButton.setText(messages.getString("Maintenance"));
        pdfButton.setText(messages.getString("GeneratePDF"));
        salirButton.setText(messages.getString("Exit"));
        notaLabel.setText(messages.getString("Note"));
        jTabbedPane1.setTitleAt(0, messages.getString("ReassignGenerate"));
        jTabbedPane1.setTitleAt(1, messages.getString("Localization"));
        jTabbedPane1.setTitleAt(2, messages.getString("device"));
        jTabbedPane1.setTitleAt(3, messages.getString("CreatePart"));
        salaLabel.setText(messages.getString("Room"));
        plantaLabel.setText(messages.getString("Floor"));
        pasilloLabel.setText(messages.getString("Hall"));
        ubicacionButton.setText(messages.getString("agregate"));
        descripcionLabel.setText(messages.getString("Description"));
        enviarButton.setText(messages.getString("Send"));
        nameLabel.setText(messages.getString("Name"));
        codPublicoLabel.setText(messages.getString("CodPublic"));
        codInternoLabel.setText(messages.getString("CodInternal"));
        marcaModel.setText(messages.getString("Brand"));
        modeloLabel.setText(messages.getString("Model"));
        garantiaLabel.setText(messages.getString("warranty"));
        ubicacionLabel.setText(messages.getString("Localization"));
        externoLabel.setText(messages.getString("Extern"));
    }//GEN-LAST:event_lenguageSelectActionPerformed

    /**
     * Funcion que recarga la información del parte que está marcado en el jList1
     */
    public void recargarMarcado() {
        String usuarioData = "";
        String parteData = "";
        String aparatoData = "";
        String incidenciaData = "";

        int index = jList1.getSelectedIndex();
        if (jList1.getSelectedIndex() == -1) {
            mantenimientoButton.setEnabled(false);
            empresaButton.setEnabled(false);
            pdfButton.setEnabled(false);
            cerrarButton.setEnabled(false);
        } else {
            mantenimientoButton.setEnabled(true);
            empresaButton.setEnabled(true);
            pdfButton.setEnabled(true);
            cerrarButton.setEnabled(true);
            parte = (Integer) listModel.getElementAt(index);
            jList1.setSelectedIndex(index);
            jList1.ensureIndexIsVisible(index);

            jLabel5.setText(String.valueOf(parte));

            //Necesito construir una supercadena.
            String texto = "";
            try {
                usuarioData = su.usuarioData(parte);
            } catch (SQLException ex) {
                Logger.getLogger(PanelSupervisor.class.getName()).log(Level.SEVERE, null, ex);
            }

            texto += usuarioData + "\n";

            try {
                parteData = Supervisor.parteData(parte);
            } catch (SQLException ex) {
                Logger.getLogger(PanelSupervisor.class.getName()).log(Level.SEVERE, null, ex);
            }

            texto += parteData + "\n";

            try {
                aparatoData = Supervisor.aparatoData(parte);
            } catch (SQLException ex) {
                Logger.getLogger(PanelSupervisor.class.getName()).log(Level.SEVERE, null, ex);
            }

            texto += aparatoData + "\n";

            try {
                incidenciaData = Supervisor.incidenciaData(parte);
            } catch (SQLException ex) {
                Logger.getLogger(PanelSupervisor.class.getName()).log(Level.SEVERE, null, ex);
            }

            texto += incidenciaData + "\n";

            jTextArea1.setText(texto);
        }
    }

    /**
     * Encargado de hacer acciones cuando se pulsa sobre un elemento del jList1
     * @param e 
     */
    @Override
    public void valueChanged(ListSelectionEvent e) {
        recargarMarcado();
    }

    /**
     * Controlador encargado de actualizar los datos del panel
     * @param evt 
     */
    private void recargarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_recargarButtonActionPerformed
        ubicacionesBoxModel.removeAllElements();
        aparatosBoxModel.removeAllElements();
        ComboBoxModel.removeAllElements();
        listModel.clear();
        listModel2.clear();
        jTextArea1.setText("");
        jLabel5.setText("??");
        try {
            ResultSet rset = Supervisor.getPartesAsignados();
            while (rset.next()) {
                listModel.addElement(rset.getInt(1));
            }
            jList1.setSelectedIndex(0);
            recargarMarcado();
            rset = Supervisor.getPartesExternos();
            while (rset.next()) {
                listModel2.addElement(rset.getInt(1));
            }
            rset = Supervisor.getAreas();
            while (rset.next()) {
                ComboBoxModel.addElement(rset.getString(1));
            }
            rset = Supervisor.getUbicaciones();
            while (rset.next()) {
                ubicacionesBoxModel.addElement(rset.getString(1));
            }
            rset = Supervisor.getAparatos();
            //ubicacionesBoxModel = new DefaultComboBoxModel();
            while (rset.next()) {
                aparatosBoxModel.addElement(rset.getString(1) + " : " + rset.getString(2) + " / " + rset.getString(3));
            }

        } catch (ClassNotFoundException ex) {
            Logger.getLogger(PanelSupervisor.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(PanelSupervisor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_recargarButtonActionPerformed

    /**
     * Controlador encargado del botón mantenimiento
     * que si se termina todo su funcionamiento
     * reasigna el parte marcado en el jList1 
     * al tecnico que seleccionemos
     * @param evt 
     */
    private void mantenimientoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mantenimientoButtonActionPerformed
        try {
            System.out.println(parte);
            //Hacer el string de personal de mantenimiento.
            Object[] possibilities = su.tecnicos();
            String s = (String) JOptionPane.showInputDialog(
                    this,
                    "Selecciona al personal de mantenimiento:\n",
                    "Mantenimiento",
                    JOptionPane.PLAIN_MESSAGE,
                    null,
                    possibilities,
                    possibilities[0]);

            //Pulsé aceptar
            if ((s != null) && (s.length() > 0)) {
                StringTokenizer st = new StringTokenizer(s, ":");
                s = st.nextToken();
                su.reasignar(Integer.parseInt(s), parte);
                recargarButtonActionPerformed(evt);
                return;
            }

            //Pulsé cancelar
            //System.out.println("Come on, finish the sentence!");
        } catch (SQLException ex) {
            Logger.getLogger(PanelSupervisor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_mantenimientoButtonActionPerformed

    /**
     * Controlador encargado del botón empresaExt
     * que si se termina todo su funcionamiento
     * reasigna el parte marcado en el jList1 
     * a la empresa que seleccionemos
     * @param evt 
     */
    private void empresaButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_empresaButtonActionPerformed
        try {
            //Hacer el string de personal de mantenimiento.
            Object[] possibilities = su.empresas();
            String s = (String) JOptionPane.showInputDialog(
                    this,
                    "Selecciona la empresa:\n",
                    "Empresa",
                    JOptionPane.PLAIN_MESSAGE,
                    null,
                    possibilities,
                    possibilities[0]);

            //Pulsé aceptar
            if ((s != null) && (s.length() > 0)) {
                StringTokenizer st = new StringTokenizer(s);
                String id = st.nextToken();
                String basura = st.nextToken();
                String cif = st.nextToken();
                String nota = jTextArea2.getText();
                boolean hecho = Supervisor.reasignar(cif, parte, nota);
                recargarButtonActionPerformed(evt);
                if (hecho) {
                    JOptionPane.showMessageDialog(this, s + messages.getString("SentSuccess"));
                } else {
                    JOptionPane.showMessageDialog(this, s + messages.getString("ImpossibleSend"));
                }
            }

            //Pulsé cancelar
            //System.out.println("Come on, finish the sentence!");
        } catch (SQLException ex) {
            Logger.getLogger(PanelSupervisor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_empresaButtonActionPerformed

    /**
     * Controlador encargado del botón de pdf
     * que si se termina todo su funcionamiento
     * genera un pdf con la información del parte
     * seleccionado en jList1 donde queramos y con el
     * nombre que queramos
     * @param evt 
     */
    private void pdfButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pdfButtonActionPerformed
        try {
            final JFileChooser fc = new JFileChooser();
            int returnVal = fc.showSaveDialog(this);
            if (returnVal == JFileChooser.APPROVE_OPTION) {//nos aseguramos q haya selecionado algun archivo
                File dir = fc.getSelectedFile();
                su.gen.CrearPdfBasico(parte, dir.toString());
            }
        } catch (SQLException ex) {
            Logger.getLogger(PanelSupervisor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_pdfButtonActionPerformed

    /**
     * Controlador encargado del botón agregar del tab ubicacion
     * que si se termina todo su funcionamiento
     * crea en la BD una nueva entrada con la información
     * recogida del panel sobre la ubicacion
     * @param evt 
     */
    private void ubicacionButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ubicacionButtonActionPerformed
        try {
            //Ubicacion
            String area = areaComboBox.getSelectedItem().toString();
            int id_area = su.getIdArea(area);
            boolean hecho = su.addUbicacion(String.valueOf(id_area), salaTextField.getText(), plantaTextField.getText(), pasilloTextField.getText());
            if (hecho) {
                JOptionPane.showMessageDialog(this, messages.getString("LocalizationCreated"));
                recargarButtonActionPerformed(evt);
            }
        } catch (SQLException ex) {
            Logger.getLogger(PanelSupervisor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_ubicacionButtonActionPerformed

    /**
     * Controlador encargado del botón agregar del tab aparato
     * que si se termina todo su funcionamiento
     * crea en la BD una nueva entrada con la información
     * recogida del panel sobre el aparato
     * @param evt 
     */
    private void aparatoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aparatoButtonActionPerformed
        try {
            //Aparato
            String sala = ubicacionesBoxModel.getSelectedItem().toString();
            String ubicacion = su.getUbicacion(sala);
            boolean hecho = su.addAparato(nombreTextField.getText(), codpublicoTextField.getText(), codinternoTextField.getText(), marcaTextField.getText(), modeloTextField.getText(), colorTextField.getText(), garantiaTextField.getText(), ubicacion);
            if (hecho) {
                JOptionPane.showMessageDialog(this, nombreTextField.getText() + messages.getString("InsertedCorrect"));
                recargarButtonActionPerformed(evt);
            }
        } catch (SQLException ex) {
            Logger.getLogger(PanelSupervisor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_aparatoButtonActionPerformed

    private void areaComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_areaComboBoxActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_areaComboBoxActionPerformed

    /**
     * Controlador encargado del botón salir, que nos devuelve a la pantalla de login
     * @param evt 
     */
    private void salirButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salirButtonActionPerformed
        this.setVisible(false);
        login.main(null);
    }//GEN-LAST:event_salirButtonActionPerformed

    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboBox1ActionPerformed

    /**
     * Controlador encargado del ComboBox de los tecnicos
     * que carga los partes que tiene asignado el tecnico seleccionado
     * en el jList1
     * @param evt 
     */
    private void tecnicosComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tecnicosComboBoxActionPerformed
        int tecnico = 0;
        String tecn = "";
        listModel.clear();
        String tec = (String) tecnicosComboBox.getSelectedItem();
        StringTokenizer st = new StringTokenizer(tec, ":");
        switch (tecnicosComboBox.getSelectedIndex()) {
            case 0:
                recargarButtonActionPerformed(evt);
                break;
            default:
                try {
                    while (st.hasMoreTokens()) {
                        st.nextToken();
                        tecn = st.nextToken();
                    }
                    ResultSet rset = Supervisor.getId_Tecnico(tecn);
                    while (rset.next()) {
                        tecnico = rset.getInt(1);
                    }
                    rset = Supervisor.getPartesAsignados(tecnico);
                    while (rset.next()) {
                        listModel.addElement(rset.getInt(1));
                    }
                } catch (SQLException ex) {
                    Logger.getLogger(PanelSupervisor.class.getName()).log(Level.SEVERE, null, ex);
                }

        }
    }//GEN-LAST:event_tecnicosComboBoxActionPerformed

    /**
     * Controlador encargado del botón enviar del tab crear parte
     * que si se termina todo su funcionamiento
     * crea en la BD una nueva entrada con la información
     * recogida del panel sobre el parte
     * @param evt 
     */
    private void enviarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_enviarButtonActionPerformed
        try {
            StringTokenizer st = new StringTokenizer(jComboBox2.getSelectedItem().toString());
            String id = st.nextToken();
            boolean hecho = Supervisor.CrearParte(id, jTextArea3.getText());
            if (hecho) {
                JOptionPane.showMessageDialog(this, messages.getString("PartCreated"));
                recargarButtonActionPerformed(evt);
            }
        } catch (SQLException ex) {
            Logger.getLogger(PanelCliente2.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_enviarButtonActionPerformed

    /**
     * Controlador encargado del botón cerrar parte
     * que cierra el parte seleccionado del jList1
     * @param evt 
     */
    private void cerrarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cerrarButtonActionPerformed
        try {
            boolean hecho = Supervisor.CerrarParte(String.valueOf(parte));
            if (hecho) {
                JOptionPane.showMessageDialog(this, messages.getString("PartClosed"));
                recargarButtonActionPerformed(evt);
            }
        } catch (SQLException ex) {
            Logger.getLogger(PanelSupervisor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_cerrarButtonActionPerformed

    /**
     * Controlador de eventos para la selección de un elemento del jList2
     * @param evt 
     */
private void jList2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jList2MouseClicked
// TODO add your handling code here:
    recargarMarcado2();
}//GEN-LAST:event_jList2MouseClicked

    /**
     * Función encargada de recargar la información del parte seleccionado de la empresa externa
     */
    public void recargarMarcado2() {
        String usuarioData = "";
        String parteData = "";
        String aparatoData = "";
        String incidenciaData = "";

        int index = jList2.getSelectedIndex();

        mantenimientoButton.setEnabled(true);
        empresaButton.setEnabled(true);
        pdfButton.setEnabled(true);
        cerrarButton.setEnabled(true);
        parte = (Integer) listModel2.getElementAt(index);
        jList2.setSelectedIndex(index);
        jList2.ensureIndexIsVisible(index);

        jLabel5.setText(String.valueOf(parte));

        //Necesito construir una supercadena.
        String texto = "";
        try {
            usuarioData = su.usuarioData(parte);
        } catch (SQLException ex) {
            Logger.getLogger(PanelSupervisor.class.getName()).log(Level.SEVERE, null, ex);
        }

        texto += usuarioData + "\n";

        try {
            parteData = Supervisor.parteData(parte);
        } catch (SQLException ex) {
            Logger.getLogger(PanelSupervisor.class.getName()).log(Level.SEVERE, null, ex);
        }

        texto += parteData + "\n";

        try {
            aparatoData = Supervisor.aparatoData(parte);
        } catch (SQLException ex) {
            Logger.getLogger(PanelSupervisor.class.getName()).log(Level.SEVERE, null, ex);
        }

        texto += aparatoData + "\n";

        try {
            incidenciaData = Supervisor.incidenciaData(parte);
        } catch (SQLException ex) {
            Logger.getLogger(PanelSupervisor.class.getName()).log(Level.SEVERE, null, ex);
        }

        texto += incidenciaData + "\n";

        jTextArea1.setText(texto);

    }

    /**
     * Procedimiento sustituto del main que carga el panel
     * @param args
     * @param q objeto QuerySupervisor para que lo pueda utilizar 
     * la clase Supervisor para hacer las consultas
     */
    public static void start(String args[], final QuerySupervisor q) {
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(PanelSupervisor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(PanelSupervisor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(PanelSupervisor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(PanelSupervisor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                PanelSupervisor panel = new PanelSupervisor(q);
                panel.setVisible(true);
                panel.setResizable(false);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton aparatoButton;
    private javax.swing.JLabel aparatoLabel;
    private javax.swing.JComboBox areaComboBox;
    private javax.swing.JLabel areaLabel;
    private javax.swing.JButton cerrarButton;
    private javax.swing.JLabel codInternoLabel;
    private javax.swing.JLabel codPublicoLabel;
    private javax.swing.JTextField codinternoTextField;
    private javax.swing.JTextField codpublicoTextField;
    private javax.swing.JLabel colorLabel;
    private javax.swing.JTextField colorTextField;
    private javax.swing.JLabel descripcionLabel;
    private javax.swing.JButton empresaButton;
    private javax.swing.JButton enviarButton;
    private javax.swing.JLabel externoLabel;
    private javax.swing.JLabel garantiaLabel;
    private javax.swing.JTextField garantiaTextField;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JList jList1;
    private javax.swing.JList jList2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextArea jTextArea2;
    private javax.swing.JTextArea jTextArea3;
    private javax.swing.JLabel lenguageLabel;
    private javax.swing.JComboBox lenguageSelect;
    private javax.swing.JLabel listaLabel;
    private javax.swing.JButton mantenimientoButton;
    private javax.swing.JLabel marcaModel;
    private javax.swing.JTextField marcaTextField;
    private javax.swing.JLabel modeloLabel;
    private javax.swing.JTextField modeloTextField;
    private javax.swing.JLabel nameLabel;
    private javax.swing.JTextField nombreTextField;
    private javax.swing.JLabel notaLabel;
    private javax.swing.JLabel parteLabel;
    private javax.swing.JLabel pasilloLabel;
    private javax.swing.JTextField pasilloTextField;
    private javax.swing.JButton pdfButton;
    private javax.swing.JLabel plantaLabel;
    private javax.swing.JTextField plantaTextField;
    private javax.swing.JButton recargarButton;
    private javax.swing.JLabel salaLabel;
    private javax.swing.JTextField salaTextField;
    private javax.swing.JButton salirButton;
    private javax.swing.JComboBox tecnicosComboBox;
    private javax.swing.JButton ubicacionButton;
    private javax.swing.JLabel ubicacionLabel;
    // End of variables declaration//GEN-END:variables
    private DefaultListModel listModel;
    private DefaultListModel listModel2;
    private DefaultComboBoxModel ComboBoxModel;
    private DefaultComboBoxModel ubicacionesBoxModel;
    private DefaultComboBoxModel tecnicosBoxModel;
    private DefaultComboBoxModel aparatosBoxModel;
}
